package com.example.autorefreshbussines.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.GetMapping;

import javax.sql.DataSource;

@Service
public class ControllerDemoService {
    @Autowired
    private DataSource dataSource;

    @Autowired
    private JdbcTemplate jdbcTemplate;

    @GetMapping("/testDb")
    public String testDb() {
        try {
            String dbProductName = dataSource.getConnection().getMetaData().getDatabaseProductName();
            return "连接成功，数据库类型：" + dbProductName;
        } catch (Exception e) {
            e.printStackTrace();
            return "连接失败";
        }
    }
}
